<template>
  <div>
    <el-card class="box-card">
      <el-table
        style="margin-bottom:20px"
        :header-cell-style="{background:'#eee'}"
        border
        :data="tableData"
      >
        <el-table-column align="center" type="index" width="50" label="序号"></el-table-column>
        <el-table-column align="center" prop="chong_money" label="充值金额"></el-table-column>
        <el-table-column align="center" prop="drive_money" label="发货金额"></el-table-column>
        <el-table-column align="center" prop="balance" label="余额"></el-table-column>
        <el-table-column align="center" prop="compound_energy" label="合成剩余能量"></el-table-column>
        <el-table-column align="center" prop="integral" label="积分"></el-table-column>
        <el-table-column align="center" prop="bag_money" label="背包成本"></el-table-column>
        <el-table-column align="center" prop="shop_drive_price" label="商城发货"></el-table-column>
        <el-table-column align="center" prop="refund_money" label="交易频道发货"></el-table-column>
        <el-table-column align="center" prop="yingkui" label="平台盈亏"></el-table-column>
        <!-- <el-table-column align="center" prop="add_time" label="时间"></el-table-column> -->
      </el-table>
      <div style="text-align:right">
        <el-pagination
          background
          layout="prev, pager, next"
          :current-page="currentPage"
          :total="total"
          @current-change="currentChange"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { userProfitandloss } from '@/api/consumer'
import { parseTime } from '@/utils/index'
export default {
  props: {
    user_id: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      // 分页数据
      total: 0,
      currentPage: 1,
      pageSize: 10,
      tableData: []
    }
  },
  mounted() {
    // this.getUserCoupon();
  },
  watch: {
    user_id(newVal, oldVal) {
      // this.getUserBalance();
    }
  },
  methods: {
    // 获取优惠券列表
    async getUserProfitandloss() {
      const res = await userProfitandloss({
        id: this.user_id,
        page: this.currentPage,
        limit: this.pageSize
      })
      console.log(res)
      this.tableData = [res.data]
      //   this.tableData.forEach(item => {
      //     item.add_time = parseTime(item.add_time, "{y}-{m}-{d} {h}:{i}:{s}");
      //   });
      this.total = res.count
    },
    queryAsk() {
      this.currentPage = 1
      this.getUserProfitandloss()
    },
    //重置
    queryReset() {
      this.resetForm('query')
      this.total = 0
      this.currentPage = 1
      this.pageSize = 10
      this.query.keywords = ''
      this.getUserProfitandloss()
    },

    //分页改变
    currentChange(current) {
      this.currentPage = current
      this.getUserProfitandloss()
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang='scss' scoped>
.box-card {
  margin-bottom: 20px;
}
.search {
  display: flex;
  align-items: center;
}
::v-deep .el-input {
  width: 292px;
  display: block;
  position: static !important;
}
::v-deep .el-input--medium .el-input__inner {
  width: 292px;
}

::v-deep .el-form-item__label {
  padding: 0 30px 0 0;
}
</style>
